package com.dqhl.community.activity;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseActivity;

/**
 * Created by LIENLIN on 2016/9/2.
 * 周边购物-立即结算
 */
public class ShoppingAccount extends BaseActivity implements View.OnClickListener {

    private ImageView mIvback;
    private TextView mTvTitle;
    private TextView mTvAllMoney;//总支付金额
    private TextView mTvNumber;//购买数量
    private ImageView mImOperation;
    private ImageView mImAdd;//加号
    private ImageView mImJian;//减号
    private TextView mTvAccount;//结算按钮
    private int num=0;//商品个数
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopping_account);

        initView();

        Intent intent=getIntent();
        Bundle bundle = intent.getExtras();
        String allmoney = bundle.getString("allmoney", 0 + "");
        num = bundle.getInt("number",0);
        if (num>0){
            mImJian.setVisibility(View.VISIBLE);
            mTvNumber.setVisibility(View.VISIBLE);
            mTvAllMoney.setText(allmoney);
            mTvNumber.setText(num+"");
        }

    }

    private void initView() {
        mIvback = (ImageView) findViewById(R.id.iv_top_back);
        mTvTitle = (TextView) findViewById(R.id.tv_top_title);
        mTvAllMoney = (TextView) findViewById(R.id.tv_shopping_allmoney);
        mImOperation = (ImageView) findViewById(R.id.tv_top_operation);
        mImAdd = (ImageView) findViewById(R.id.iv_account_jia);
        mImJian = (ImageView) findViewById(R.id.iv_account_jian);
        mTvNumber = (TextView) findViewById(R.id.tv_account_number);
        mTvAccount = (TextView) findViewById(R.id.tv_account);

        mIvback.setVisibility(View.VISIBLE);
        mImOperation.setVisibility(View.INVISIBLE);
        mIvback.setOnClickListener(this);
        mImAdd.setOnClickListener(this);
        mImJian.setOnClickListener(this);
        mTvAccount.setOnClickListener(this);
        mTvTitle.setText(R.string.txt_shoping);

        mTvNumber.setText(num+"");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_top_back:
                finish();
                break;
            case R.id.iv_account_jia:
                ++num;
                if (num==1){
                    mImJian.setVisibility(View.VISIBLE);
                    mTvNumber.setVisibility(View.VISIBLE);
                }
                mTvNumber.setText(num+"");
                mTvAllMoney.setText(18.00*num+"");
                break;
            case R.id.iv_account_jian:
                if (num>0){
                    mTvNumber.setText(--num+"");
                    mTvAllMoney.setText(18.00*num+"");
                    if (num==0){
                        mImJian.setVisibility(View.GONE);
                        mTvNumber.setVisibility(View.GONE);
                    }
                }
                break;
            case R.id.tv_account:
                if (num>0){
                    new AlertDialog.Builder(this).setMessage("支付成功！\n"+mTvAllMoney.getText()).show();
                }
                break;
        }
    }
}
